package com.zhihuichongcheng.application.ui.task.adapter.holder;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.smartlib.cmnObject.dialog.DialogOnClick;
import com.smartlib.cmnObject.util.DialogUtil;
import com.smartlib.cmnObject.util.StringUtil;
import com.zhihuichongcheng.application.R;

/**
 * data Created by LK on 2017/1/6.
 */
public class FilterDataHolder extends RecyclerView.ViewHolder {
    private View dateLayout;
    private TextView mTvDate;
    private String finishTime = "";
    private TextView mBtnClear;


    public FilterDataHolder(View itemView) {
        super(itemView);
        ((TextView) itemView.findViewById(R.id.layout_head).findViewById(R.id.tv_name)).setText("截止时间");
        mTvDate = (TextView) itemView.findViewById(R.id.tv_date);
        dateLayout = itemView.findViewById(R.id.tv_date_layout);
        mBtnClear = (TextView) itemView.findViewById(R.id.btn_clear);
    }

    public String getData() {
        if (finishTime.contains("年") || finishTime.contains("-"))
            return finishTime.replace(" ", "").replace("年", "-").replace("月", "-").replace("日", "") + " 23:59:59";
        else
            return "";
    }

    public void setData(String finishTime) {
        setData();
        if (!StringUtil.isEmpty(finishTime)) {
            this.finishTime = finishTime;
            mTvDate.setText(finishTime);
            mBtnClear.setVisibility(View.VISIBLE);
        }
    }

    public void setData() {
        dateLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                DialogUtil.showDatePick(itemView.getContext(), new DialogOnClick<String>() {
                    @Override
                    public void onClick(String s) {
                        String[] source = s.split("-");
                        String year = source[0];
                        String month = source[1];
                        String day = source[2];
                        finishTime = year + " 年 " + month + " 月 " + day + " 日 ";
                        mBtnClear.setVisibility(View.VISIBLE);
                        mTvDate.setText(finishTime);
                    }
                });
            }
        });
        mBtnClear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finishTime = "";
                mBtnClear.setVisibility(View.GONE);
                mTvDate.setText("0000 年 00 月 00日");
            }
        });
    }
}
